package com.gwnet.shop.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.log.annotation.Log;
import com.gwnet.common.log.enums.BusinessType;
import com.gwnet.common.mybatis.core.page.TableDataInfo;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.shop.domain.OrderGoods;
import com.gwnet.shop.service.IOrderGoodsService;
import com.gwnet.shop.utils.AjaxResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 订单货品Controller
 * @author zhangwanpeng
 * @date 2024-07-21
 */
@RestController
@RequestMapping("/ordergoods")
public class OrderGoodsController extends MBaseController
{
    @Resource
    private IOrderGoodsService orderGoodsService;

    /**
     * 查询订单货品列表
     */
    @SaCheckPermission("shop:ordergoods:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderGoods orderGoods)
    {
        startPage();
        List<OrderGoods> list = orderGoodsService.selectOrderGoodsList(orderGoods);
        return getDataTable(list);
    }


    /**
     * 获取订单货品详细信息
     */
    @SaCheckPermission("shop:ordergoods:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderGoodsService.selectOrderGoodsById(id));
    }

    /**
     * 新增订单货品
     */
    @SaCheckPermission("shop:ordergoods:add")
    @Log(title = "订单货品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderGoods orderGoods)
    {
        orderGoods.setCreateBy( LoginHelper.getUserId() );
        return toAjax(orderGoodsService.insertOrderGoods(orderGoods));
    }

    /**
     * 修改订单货品
     */
    @SaCheckPermission("shop:ordergoods:edit")
    @Log(title = "订单货品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderGoods orderGoods)
    {
        orderGoods.setCreateBy( LoginHelper.getUserId() );
        return toAjax(orderGoodsService.updateOrderGoods(orderGoods));
    }

    /**
     * 删除订单货品
     */
    @SaCheckPermission("shop:ordergoods:remove")
    @Log(title = "订单货品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderGoodsService.deleteOrderGoodsByIds(ids));
    }
}
